<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>AJAX get方法使用</title>
</head>
<body>
	<form id="fm" action="">
		姓名：<input id="name" type="text" name="name" value="">
		地址：<input id="address" type="text" name="address" value="">
		<input id="btn" type="button" value="AJAX get提交">
		<input id="formbtn" type="button" value="AJAX提交">
	</form>
	<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
	<script>
		// $.get()方法
		$('#btn').click(function(){
			var name = $('#name').val();
			var address = $('#address').val();
			if(name == '' || address == ''){
				alert('error');
				return;
			}
			$.get('../php/get.php',{name:name,address:address},function(res){
				console.log(res);
			});
		});
		// 使用 $.ajax()
		$('#formbtn').click(function(){
			var name = $('#name').val();
			var address = $('#address').val();
			if(name == '' || address == ''){
				alert('error');
				return;
			}
			$.ajax({
		            url: "../php/get.php",
		            type: "get",
		            data: {name:name,address:address},
		            success: function (data) {
		               	console.log(data);
		            },
		            error: function () {
		                alert('上传失败');
		            }
		        });
		});
	</script>
</body>
</html>